<?php
namespace ZyucMini\Components\Expert\Models;

use ZyucMini\Core\Model;

// 专家任务表
class Task extends Model
{
    protected $connection = 'uxt';
    protected $table = 'exp_task';

    // 获取一周的任务列表
    public function getTaskByWeek()
    {
        $start_time = date('Y-m-d 00:00:00', strtotime('-1 week'));
        $end_time = date('Y-m-d 23:59:59', strtotime('-1 day'));
        $rows = $this
            ->newQuery()
            ->where('task_status IN (2, 3, 4, 5, 6, 7, 8)', [])
            ->where('assign_time BETWEEN ? AND ?', [$start_time, $end_time])
            ->where('update_at BETWEEN ? AND ?', [$start_time, $end_time])
            // ->orWhere([
            //     [('assign_time BETWEEN ? AND ?'), [ $start_time , $end_time]],
            //     [('update_at BETWEEN ? AND ?'), [ $start_time , $end_time]],
            // ])
            ->fields('id, project_id, task_status, assign_time, task_handle, task_content,task_require_bg')
            ->all();
        // 筛选已完成的
        foreach ($rows as &$row) {
            $status = intval($row['task_status']);
            $row['is_finish'] = false;
            if ($status === 3 || $status === 4 || $status === 8) {
                $row['is_finish'] = true;
            }
        }
        return $rows;
    }

    // 查询已完成
    public function getCompleteds() {
        $model = $this->newQuery();
        $model->where('task_status IN (3, 4, 8)', []);
        return $model;
    }

    // 查询进行中
    public function getInProgress() {
        $model = $this->newQuery();
        $model->where('task_status IN (2, 5, 6)', []);
        return $model;
    }
}
?>